package com.reshare.service;

import com.reshare.base.BaseService;
import com.reshare.bean.Module;
import com.reshare.dto.TreeDto;
import com.reshare.mapper.ModuleMapper;
import com.reshare.mapper.PermissionMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ModuleService  extends BaseService<Module,Integer> {

     @Resource
     private ModuleMapper moduleMapper;

     @Resource
     private PermissionMapper permissionMapper;


     public List<TreeDto> findModues() {
          return moduleMapper.selectModules();
     }

     public List<TreeDto> findModules2(Integer roleId) {
               //查询用户所有资源信息
               List<TreeDto> tList = findModues();
               //查询当前角色拥有的资源id集合
          List<Integer> idList=permissionMapper.selectRoleHasAllModuleIds(roleId);
          //遍历
          //判断当前角色是否用有资源id
          if (idList!=null|| idList.size()>0){
               for (TreeDto treeDto:tList){
                    //当前角色的mid，是否在全体资源出现过
                    if (idList.contains(treeDto.getId())){
                         treeDto.setChecked(true);
                    }
               }
          }
          return tList;
          }


     }
